// $Id: headers.h 100 2011-10-21 15:05:36Z cedric.shih@gmail.com $
/*
 * Copyright 2011 Cedric Shih (cedric dot shih at gmail dot com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef CODEC_HEADERS_H_
#define CODEC_HEADERS_H_

#include <sys/types.h>

enum niohttp_headers_decoder_state {
	NIOHTTP_HEADER_NAME,
	NIOHTTP_HEADER_VALUE,
	NIOHTTP_HEADER_ENTRY,
	NIOHTTP_HEADER,
	NIOHTTP_HEADERS,
};

struct niohttp_headers;

struct niohttp_headers_decoder {
	enum niohttp_headers_decoder_state state;
	struct niohttp_headers *headers;
	ssize_t offset1;
	ssize_t offset2;
};

struct niohttp_headers_decoder *niohttp_headers_decoder_new(void);

void niohttp_headers_decoder_free(
		struct niohttp_headers_decoder *codec);

int niohttp_headers_decoder_reset(
		struct niohttp_headers_decoder *decoder,
		struct niohttp_headers *headers);

struct zcbuffer;

int niohttp_headers_decoder_parse(
		struct niohttp_headers_decoder *decoder,
		struct zcbuffer *buffer, struct niohttp_headers **headers);

int niohttp_headers_format(struct niohttp_headers *headers,
		struct zcbuffer *buffer);

#endif /* CODEC_HEADERS_H_ */
